|
|
|
|
|
|
|
Now save and run the project. This time, click the Seek button. When the dialog box appears, accept the default value of 10 and click OK. You should see a message telling you that the search was successful (see Figure 10.2). |
|
|
|
|
|
|
|
|
Figure 10.2.
The results of the Seek method on a table object. |
|
|
|
|
| |
|
|
|
|
You can use other comparison values besides = with the Seek method. You can use <, <=, =, >=, or > as a comparison value. |
|
|
|
|
|
|
|
|
|
|
Although Seek is the fastest search method, you can apply it only to Recordsets opened as table objects. If you want to locate a specific record in a Dynaset or Snapshot, use one of the Find methods. |
|
|
|
|
|
|
|
|
Using Find on Non-Table Recordsets |
|
|
|
|
|
|
|
|
Because Dynaset and Snapshot objects do not use indexes, you cannot use the Seek method to search for specific records within them. The Find method is used to locate specific records in non-table objects (Dynasets and Snapshots). The Find method is a sequential search; it starts at the beginning of the dataset and looks at each record until it finds one that matches the search criteria. Although this method is not as fast as Seek, it is still faster than using the Move methods to handle this operation within your own Visual Basic code. |
|
|
|
|
|
|
|
|
The syntax for the Find methods is almost identical to the SQL WHERE clause (covered in Day 8). The search string consists of a field (or set of fields) followed by a comparison operator (=,<>, and so on) and a search value (for example, MyRS.FindFirst "Au_ID=13"). |
|
|
|
|
|
|
|
|
There are actually four Find methods: FindFirst, FindPrevious, FindNext, and FindLast. The FindFirst method starts its search from the beginning of the file. The FindLast method starts its search from the end of the file and works its way to the beginning. You can use the FindPrevious and FindNext methods to continue a search that can return more than one record. For example, if you are looking for all the records that have their ZipCode column set to 99999, you could use the FindFirst method to locate the first record and then use the FindNext method to continue the search forward until you reach the end of the dataset. Similarly, you can use the FindLast and FindPrevious methods to perform continued searches starting at the end of the dataset. Although the FindNext and FindPrevious methods are available, it is usually better to create a new Recordset using the Find criteria if you expect to locate more than one record that meets the criteria. |
|
|
|
|
|